<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function LinkedList(){
            // 构建节点类
            function Node(val)
            {
                this.val = val 
                this.next = null
            }

            // 属性
            this.head = null 
            this.lenght = 0

            //append(element) 往链表最后的位置追加一个节点
             LinkedList.prototype.append = function(val){
                var newnode = new Node(val)
                if(this.lenght==0 ){
                    this.head = newnode
                }else{
                    
                    var current = this.head
                    while(current.next){
                        current = current.next
                    }
                    current.next = newnode  
                }
                this.lenght++
             }
            //insert(position,element) 插入到固定位置

            //removeAt(position) 删除链表第 position 个元素

            // remove(element) 删除对应的节点

            //update(element) 修改

            //get(position) 获取对应位置元素

            // indexOf(element) 返回该元素对应的索引

            // toString
            LinkedList.prototype.toString = function(){
                let current  = this.head
                let res = ''
                while(current)
                {
                    res+=current.val+' '
                    current = current.next
                }
                return res
            }
        }

        var list = new LinkedList()
        list.append('first')
        list.append('second')
        list.append('3')
        list.append('55')
        console.log(list.toString());
        console.log(list)   ;
        



    </script>
</body>
</html>